
#include <stdio.h>
 
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
 
 

	int x,y;				 
	int velocity_x,velocity_y ;
	int left,right,top,bottom;  
 
 
void gotoxy(int x,int y)  
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(handle,pos);
}
 
 
void HideCursor() 
{
	CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void startup() 
{
	x = 1;
	y = 5;
	velocity_x = 1;			
	velocity_y = 1;
	left = 0;
	right = 30;
	top = 0;
	bottom = 15;
 
 
	HideCursor(); 	
}
 
 
void show()  
{
	
	int i,j;
	for (i=0;i<=bottom;i++)
	{
		for (j=0;j<=right;j++)
		{
 
 
	
			if((i==x) && (j==y))
				{
					printf("o");			
				}
			else if ((i==0)||(i==bottom)||(j==0)||(j==right))	
				{
					printf("#");
				}
			else	printf(" ");
		}
		printf("\n");
	}
}	
void automation()  
{	
	x = x + velocity_x;			 
	y = y + velocity_y;
	if ((x==top)||(x==bottom))
	{
		velocity_x = -velocity_x;
		printf("\a");
	}
		
	else if ((y==left)||(y==right))
	{
		velocity_y = -velocity_y;
		printf("\a");
	}
			
	Sleep(100);		 
}
int main()
{
	system("color 2f");		
	startup();  		
	while (1) 				
	{
		gotoxy(0,0);  		
		show();  			
		automation();  	
	}
	return 0;
}




